var REPORT_PATH_PREFIX = "";
var TODO_PATH = "";

function setReportPath(path){
	REPORT_PATH_PREFIX =  path;
}

function setPathPreTodo(path){
	TODO_PATH = path;
}

$(function() {
	$('#reportType').select2({
		placeholder : "报告类型"
	});
	WASP_WIDGET.triggerDateRangeStyle("reportDate");
	WASP_WIDGET.triggerPrdInfoSelect("prdCode");
	initValidate();
	WASP_WIDGET.triggerICheck();
});

//表单验证
function initValidate(){
	 $("#regulatoryReportForm").validate({
	        focusCleanup: true,
	        ignore : "",
	        rules: {
	        	prdCode:{
	            	required: true	
	            },
	            reportDate : {
	            	required: true
				},
	        },
	        messages: {
	        	prdCode : "请选择产品",
	        	reportDate : "请选择报告日期",
	        }
	    });
	 
}

function down() {
	var reportTypeStr = $("input[name='reportType']:checked");
	var reportType = "";
	reportTypeStr.each(function(){
		reportType += $(this).val() + ",";
	});
	
	if(null == reportType || reportType == ''){
		ctools.alert('请选择报告类型!',"","warning");
		return;
	}
	var reportDate = $("#reportDate").val().split("-");
	var reprotDateBgn = reportDate[0].trim();
	var reprotDateEnd = reportDate[1].trim();
	
	$.ajax({
		type:"GET",
		url: REPORT_PATH_PREFIX + "/checkAttachFile.do",
		data:{"reprotDateBgn" : reprotDateBgn,
			  "reprotDateEnd" : reprotDateEnd,
			  "reportType": reportType
			},
		cache:false,
		dataType:"json",
		success:function(data){
			if(data.success){
				window.location.href=encodeURI(REPORT_PATH_PREFIX+"/batchDownAttachByType.do?reportType="+reportType+"&reprotDateBgn="+reprotDateBgn+"&reprotDateEnd="+reprotDateEnd);
			}else {
				ctools.alert('该类型未上传报告!',"","warning");
			}
		}
	});
}


